package com.apigen.platform.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * API端点请求DTO
 *
 * @author API Generator Platform
 * @since 2024-09-24
 */
@Data
@Schema(description = "API端点配置参数")
public class ApiEndpointRequest {

    @Schema(description = "端点ID（更新时必填）", example = "1")
    private Long endpointId;

    @NotBlank(message = "端点名称不能为空")
    @Schema(description = "端点名称", example = "获取用户列表")
    private String endpointName;

    @NotBlank(message = "端点路径不能为空")
    @Pattern(regexp = "^/.*", message = "端点路径必须以/开头")
    @Schema(description = "端点路径", example = "/api/users")
    private String endpointPath;

    @NotBlank(message = "HTTP方法不能为空")
    @Pattern(regexp = "^(GET|POST|PUT|DELETE|PATCH)$", message = "HTTP方法必须是GET、POST、PUT、DELETE、PATCH之一")
    @Schema(description = "HTTP方法", example = "GET", allowableValues = {"GET", "POST", "PUT", "DELETE", "PATCH"})
    private String httpMethod;

    @NotNull(message = "关联表ID不能为空")
    @Schema(description = "关联表ID", example = "1")
    private Long tableId;

    @Schema(description = "端点描述", example = "分页获取用户列表，支持条件筛选")
    private String description;

    @Schema(description = "启用分页", example = "true")
    private Boolean enablePagination = true;

    @Schema(description = "启用排序", example = "true")
    private Boolean enableSorting = true;

    @Schema(description = "启用筛选", example = "true")
    private Boolean enableFiltering = true;

    @Schema(description = "响应格式", example = "JSON", allowableValues = {"JSON", "XML"})
    private String responseFormat = "JSON";

    @NotNull(message = "所属项目ID不能为空")
    @Schema(description = "所属项目ID", example = "1")
    private Long projectId;

    @Schema(description = "请求参数配置")
    private List<ApiParameterConfig> requestParameters;

    @Schema(description = "响应字段配置")
    private List<ApiFieldConfig> responseFields;

    @Data
    @Schema(description = "API参数配置")
    public static class ApiParameterConfig {

        @Schema(description = "参数名称", example = "username")
        private String paramName;

        @Schema(description = "参数类型", example = "String")
        private String paramType;

        @Schema(description = "参数位置", example = "QUERY", allowableValues = {"QUERY", "PATH", "BODY", "HEADER"})
        private String paramLocation;

        @Schema(description = "是否必填", example = "false")
        private Boolean required = false;

        @Schema(description = "参数描述", example = "用户名筛选条件")
        private String description;

        @Schema(description = "默认值", example = "")
        private String defaultValue;

        @Schema(description = "示例值", example = "admin")
        private String exampleValue;
    }

    @Data
    @Schema(description = "API字段配置")
    public static class ApiFieldConfig {

        @Schema(description = "字段名称", example = "userId")
        private String fieldName;

        @Schema(description = "字段类型", example = "Long")
        private String fieldType;

        @Schema(description = "是否包含在响应中", example = "true")
        private Boolean included = true;

        @Schema(description = "字段描述", example = "用户ID")
        private String description;

        @Schema(description = "示例值", example = "1000")
        private String exampleValue;
    }
}











